package com.hznu.jspFinal.service;


import com.hznu.jspFinal.dao.AnswerRecordMapper;
import com.hznu.jspFinal.dao.ExamRecordMapper;
import com.hznu.jspFinal.entity.AnswerRecord;
import com.hznu.jspFinal.entity.ExamRecord;
import com.hznu.jspFinal.myBeans.ExamAnswerDetail;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ExamRecordServiceImpl implements ExamRecordService{

    @Autowired
    ExamRecordMapper examRecordMapper;
    @Autowired
    AnswerRecordMapper answerRecordMapper;

    @Override
    public void addOne(ExamAnswerDetail examAnswerDetail)
    {

    }

    @Override
    public void modify(ExamAnswerDetail examAnswerDetail)
    {
        AnswerRecord answerRecord = examAnswerDetail.getAnswerRecord();
        ExamRecord examRecord = examAnswerDetail.getExamRecord();

        AnswerRecord t = answerRecordMapper.selectByCondition(answerRecord);
        if(t!=null)
        {
            examRecord.setAnswerrecordid(t.getId());
            examRecordMapper.updateByAnswerrecordidSelective(examRecord);
        }else
        {
            answerRecordMapper.insertSelective(answerRecord);
            examRecord.setAnswerrecordid(answerRecord.getId());
            examRecordMapper.insertSelective(examRecord);
        }

    }

    @Override
    public List<ExamRecord> findByStudent(AnswerRecord answerRecord)
    {
        return examRecordMapper.selectByStudent(answerRecord);
    }

    @Override
    public ExamRecord findByExercise(AnswerRecord answerRecord)
    {
        return examRecordMapper.selectByExercise(answerRecord);
    }
}
